package com.cxp.serverdemo.config;

import com.cxp.serverdemo.common.DateConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 这里是有关MVC的配置
 * 可以对SPRING的验证器、格式化器、拦截器、视图控制器等等
 *
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    //添加一个时间格式化处理器
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new DateConverter());
    }

    /*
    * 创建一个JAVA线程池（有四程线程池）
    * CachedThreadPool：可重用闲置的线程，没有则创建，闲置60秒则销毁
    * */
    @Bean
    public ExecutorService executorService() {
        return Executors.newCachedThreadPool();
    }
}
